using System;
using System.Collections.Generic;
using System.Text;

using Csla;
using Csla.Data;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;


namespace buildingLib.Prepare
{
    [Serializable()]
    public class AreaLogical : BusinessBase<AreaLogical>
    {
        #region Business Methods
        Guid m_id;
        double m_t4sellAll;
        double m_nonpubadd;
        double m_renfang;
        double m_outadd;
        double m_inminus;
        double m_total4;
        double m_t1total;
        double m_value1;
        double m_t3total;
        double m_nonpubminus;
        double m_outminus;
        double m_inadd;
        double m_total3;
        double m_t4total;
        double m_value2;

        public Guid ID
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_id;
            }
        }

        public double T4sellAll
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_t4sellAll;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                CanWriteProperty(true);
                if (m_t4sellAll != value)
                {
                    m_t4sellAll = value;
                    PropertyHasChanged();
                }
            }
        }
        public double Nonpubadd
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_nonpubadd;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                CanWriteProperty(true);
                if (m_nonpubadd != value)
                {
                    m_nonpubadd = value;
                    PropertyHasChanged();
                }
            }
        }
        public double Renfang
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_renfang;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                CanWriteProperty(true);
                if (m_renfang != value)
                {
                    m_renfang = value;
                    PropertyHasChanged();
                }
            }
        }
        public double Outadd
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_outadd;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                CanWriteProperty(true);
                if (m_outadd != value)
                {
                    m_outadd = value;
                    PropertyHasChanged();
                }
            }
        }
        public double Inminus
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_inminus;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                CanWriteProperty(true);
                if (m_inminus != value)
                {
                    m_inminus = value;
                    PropertyHasChanged();
                }
            }
        }
        public double Total4
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_total4;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                CanWriteProperty(true);
                if (m_total4 != value)
                {
                    m_total4 = value;
                    PropertyHasChanged();
                }
            }
        }
        public double T1total
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_t1total;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                CanWriteProperty(true);
                if (m_t1total != value)
                {
                    m_t1total = value;
                    PropertyHasChanged();
                }
            }
        }
        public double Value1
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_value1;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                CanWriteProperty(true);
                if (m_value1 != value)
                {
                    m_value1 = value;
                    PropertyHasChanged();
                }
            }
        }
        public double T3total
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_t3total;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                CanWriteProperty(true);
                if (m_t3total != value)
                {
                    m_t3total = value;
                    PropertyHasChanged();
                }
            }
        }
        public double Nonpubminus
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_nonpubminus;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                CanWriteProperty(true);
                if (m_nonpubminus != value)
                {
                    m_nonpubminus = value;
                    PropertyHasChanged();
                }
            }
        }
        public double Outminus
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_outminus;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                CanWriteProperty(true);
                if (m_outminus != value)
                {
                    m_outminus = value;
                    PropertyHasChanged();
                }
            }
        }
        public double Inadd
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_inadd;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                CanWriteProperty(true);
                if (m_inadd != value)
                {
                    m_inadd = value;
                    PropertyHasChanged();
                }
            }
        }
        public double Total3
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_total3;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                CanWriteProperty(true);
                if (m_total3 != value)
                {
                    m_total3 = value;
                    PropertyHasChanged();
                }
            }
        }
        public double T4total
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_t4total;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                CanWriteProperty(true);
                if (m_t4total != value)
                {
                    m_t4total = value;
                    PropertyHasChanged();
                }
            }
        }
        public double Value2
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                CanReadProperty(true);
                return m_value2;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                CanWriteProperty(true);
                if (m_value2 != value)
                {
                    m_value2 = value;
                    PropertyHasChanged();
                }
            }
        }

        protected override object GetIdValue()
        {
            return m_id;
        }
        #endregion

        #region Validation Rules

        protected override void AddBusinessRules()
        {
            // TODO: add validation rules
            //ValidationRules.AddRule(null, "");
        }

        #endregion

        #region Authorization Rules

        protected override void AddAuthorizationRules()
        {
            // TODO: add authorization rules
            //AuthorizationRules.AllowWrite("", "");
        }

        #endregion

        #region Factory Methods

        public static AreaLogical GetAreaLogical(Guid id)
        {
            return DataPortal.Fetch<AreaLogical>(new Criteria(id));
        }

       
        private AreaLogical()
        {
            
        }

       

        #endregion

        #region Data Access
        [Serializable()]
        private class Criteria
        {
            private Guid _id;
            public Guid Id
            {
                get { return _id; }
            }

            public Criteria(Guid id)
            { _id = id; }
        }

        private void DataPortal_Fetch(Criteria criteria)
        {
            Database db = SQLDatabase.GetDatabase();
            DbCommand dbcom = db.GetStoredProcCommand("usp_AGetAreaLogical");
            db.AddInParameter(dbcom, "id", DbType.Guid, criteria.Id);

            using (SafeDataReader dr = new SafeDataReader(db.ExecuteReader(dbcom)))
            {
                if (dr.Read())
                {
                    m_id = dr.GetGuid("buildingid");

                    m_t4sellAll = dr.GetDouble("t4sellAll");
                    m_nonpubadd = dr.GetDouble("nonpubadd");
                    m_renfang = dr.GetDouble("renfang");
                    m_outadd = dr.GetDouble("outadd");
                    m_inminus = dr.GetDouble("inminus");
                    m_total4 = dr.GetDouble("total4");
                    m_t1total = dr.GetDouble("t1total");
                    m_value1 = dr.GetDouble("value1");
                    m_t3total = dr.GetDouble("t3total");
                    m_nonpubminus = dr.GetDouble("nonpubminus");
                    m_outminus = dr.GetDouble("outminus");
                    m_inadd = dr.GetDouble("inadd");
                    m_total3 = dr.GetDouble("total3");
                    m_t4total = dr.GetDouble("t4total");
                    m_value2 = dr.GetDouble("value2");
                }
            }
           
        }

        //internal void Insert()
        //{
        //    if (!this.IsDirty) return;
        //    Database db = SQLDatabase.GetDatabase();
        //    DbCommand dbcom = db.GetStoredProcCommand("usp_GInsertAreaLogical");
        //    db.AddOutParameter(dbcom, "id", DbType.Guid, m_id);
        //    DoInsertUpdate(dbcom);
        //    m_id = (Guid)db.GetParameterValue(dbcom, "id");
        //    MarkOld();
        //}

        //internal void Update()
        //{
        //    if (!this.IsDirty) return;
        //    Database db = SQLDatabase.GetDatabase();
        //    DbCommand dbcom = db.GetStoredProcCommand("usp_GUpdateAreaLogical");
        //    db.AddInParameter(dbcom, "id", DbType.Guid, m_id);

        //    DoInsertUpdate(dbcom);
        //    MarkOld();
        //}

        //private void DoInsertUpdate(DbCommand dbcom)
        //{
        //    Database db = SQLDatabase.GetDatabase();
        //    db.AddInParameter(dbcom, "t4sellAll", DbType.Single, m_t4sellAll);
        //    db.AddInParameter(dbcom, "nonpubadd", DbType.Single, m_nonpubadd);
        //    db.AddInParameter(dbcom, "renfang", DbType.Single, m_renfang);
        //    db.AddInParameter(dbcom, "outadd", DbType.Single, m_outadd);
        //    db.AddInParameter(dbcom, "inminus", DbType.Single, m_inminus);
        //    db.AddInParameter(dbcom, "total4", DbType.Single, m_total4);
        //    db.AddInParameter(dbcom, "t1total", DbType.Single, m_t1total);
        //    db.AddInParameter(dbcom, "value1", DbType.Single, m_value1);
        //    db.AddInParameter(dbcom, "t3total", DbType.Single, m_t3total);
        //    db.AddInParameter(dbcom, "nonpubminus", DbType.Single, m_nonpubminus);
        //    db.AddInParameter(dbcom, "outminus", DbType.Single, m_outminus);
        //    db.AddInParameter(dbcom, "inadd", DbType.Single, m_inadd);
        //    db.AddInParameter(dbcom, "total3", DbType.Single, m_total3);
        //    db.AddInParameter(dbcom, "t4total", DbType.Single, m_t4total);
        //    db.AddInParameter(dbcom, "value2", DbType.Single, m_value2);

        //    db.ExecuteNonQuery(dbcom);
        //}

        //internal void DeleteSelf()
        //{
        //    // if we're not dirty then don't update the database
        //    if (!this.IsDirty) return;

        //    // if we're new then don't update the database
        //    if (this.IsNew) return;

        //    Database db = SQLDatabase.GetDatabase();
        //    DbCommand dbcom = db.GetStoredProcCommand("usp_GDeleteAreaLogical");
        //    db.AddInParameter(dbcom, "id", DbType.Guid, m_id);

        //    db.ExecuteNonQuery(dbcom);

        //    MarkNew();
        //}

        #endregion
    }//end of class	
}//end of namespace 

